package uk.ac.bath.domains.misc;

import uk.ac.bath.legacy.Point;
import uk.ac.bath.legacy.Space;
import uk.ac.bath.util.*;

abstract public class Space2D extends Space {

    public Space2D(int sizeX, int sizeY, int sizeZ) {
        super(sizeX, sizeY, sizeZ);
    }

    protected Point2DInt rawAdjacentPoint(Point p1, int n) {
        Point2DInt p = (Point2DInt) p1.clone();
        switch (n) {
            case 1:
                p.x++;
                break;
            case 2:
                p.x--;
                break;
            case 3:
                p.y++;
                break;
            case 4:
                p.y--;
                break;
        }
        return p;
    }

    public Point randomPoint() {
        Point p = new Point2DInt(MyRandom.nextInt(sizeX), MyRandom.nextInt(sizeY));
        return p;
    }

    protected Point2DInt rawRandomPointNear(Point p, int n) {
        Point2DInt p2 = (Point2DInt) p;
        int dx = n - MyRandom.nextInt(n * 2 + 1);
        int dy = n - MyRandom.nextInt(n * 2 + 1);
        int x = p2.x + dx;
        int y = p2.y + dy;
        return new Point2DInt(x, y);
    }
}

